﻿// ===============================================================================
//  Copyright © ymind.net. All rights reserved .
//  官方网站：http://ymind.net/
//  版权所有：彦铭工作室 老陈出品
// ===============================================================================

using System;

namespace Lcsoft.UrlRewriter.Actions
{
	/// <summary>
	/// 提供设置当前请求的 Url 的映射地址功能的地址重写动作。
	/// </summary>
	public abstract class SetLocationAction : IRewriteAction
	{
		/// <summary>
		/// 初始化 <see cref="SetLocationAction"/> 类的新实例。
		/// </summary>
		/// <param name="location">映射地址。</param>
		protected SetLocationAction(string location)
		{
			if (location == null) throw new ArgumentNullException("location");

			this.Location = location;
		}

		/// <summary>
		/// 获取映射地址。
		/// </summary>
		public string Location { get; private set; }

		#region IRewriteAction Members

		/// <summary>
		/// 执行动作。
		/// </summary>
		/// <param name="context"><see cref="RewriteContext"/> 对象的实例。</param>
		/// <returns>返回 <see cref="RewriteProcessing"/> 枚举值之一。</returns>
		public virtual RewriteProcessing Execute(RewriteContext context)
		{
			if (context == null) throw new ArgumentNullException("context");

			context.Location = context.ResolveLocation(context.Expand(this.Location));

			return RewriteProcessing.StopProcessing;
		}

		#endregion
	}
}
